﻿using Owin;
using System.Net.Http.Formatting;
using System.Web.Http;

namespace CmdHost
{
    public class Startup
    {
        public void Configuration(IAppBuilder appBuilder)
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            //采用Jil Json解析替换 系统自带json解析
            config.Formatters.RemoveAt(0);
            config.Formatters.Insert(0, new JilFormatter());

            var jsonFormatter = new JsonMediaTypeFormatter();
            config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter));
            //注册全局过滤器
            config.Filters.Add(new CommonAttribute());
            config.Filters.Add(new ApiErrorHandleAttribute());
            
            appBuilder.UseWebApi(config);

        }
    }

}
